<?=view('header.html')?>

<body class="layui-view-body bgwhite">
    <div class="layui-content" style="margin-bottom: 0px; padding-bottom: 0px;">
        <div class="layui-row">
            <div class="layui-cards">
                <div class="layui-card-body">
                    <form class="layui-form" method="post" name="myform" id="myform">
                        
                        <div class="layui-form-item">
                            <label class="layui-form-label">分组名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="data[name]" value="<?=isset($data['name']) ? $data['name'] : ''?>" id="ams_name" lay-verify="required" placeholder="请输入分组名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">售价</label>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="text" name="data[price]" value="<?=isset($data['price']) ? $data['price'] : ''?>" placeholder="价格" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline" style="width: 190px;">
                                <select name="data[limit]">
                                    <option value="">-选择-</option>
                                    <option <?php if(isset($data['limit']) && $data['limit']=='hour'){echo 'selected';} ?> value="hour">按小时付费</option>
                                    <option <?php if(isset($data['limit']) && $data['limit']=='day'){echo 'selected';} ?> value="day">按天付费</option>
                                    <option <?php if(isset($data['limit']) && $data['limit']=='month'){echo 'selected';} ?> value="month">按月付费(31天/月)</option>
                                    <option <?php if(isset($data['limit']) && $data['limit']=='year'){echo 'selected';} ?> value="year">按年付费(365天/年)</option>
                                    <option <?php if(isset($data['limit']) && $data['limit']=='ever'){echo 'selected';} ?> value="ever">永不过期</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">过期变为</label>
                            <div class="layui-input-inline">
                                <select class="form-control" name="data[overdue]">
                                    <option value="">-选择-</option>
                                    <?php if(isset($groups) && $groups):?>
                                    <?php foreach($groups as $g):?>
                                    <option <?php if(isset($data['overdue']) && $g['id']==$data['overdue']){echo 'selected';}?> value="<?=$g['id']?>"><?=$g['name']?></option>
                                    <?php endforeach;?>
                                    <?php endif;?>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item" lay-filter="sex">
                            <label class="layui-form-label">注册开关</label>
                            <div class="layui-input-block">
                                <input type="radio" name="data[allowregister]" value="1" title="开放注册" <?php if((isset($data['allowregister']) && $data['allowregister']=='1') || !isset($data['allowregister'])){echo 'checked';} ?>>
                                <input type="radio" name="data[allowregister]" value="0" title="关闭注册" <?php if(isset($data['allowregister']) && $data['allowregister']=='0'){echo 'checked';} ?>>
                            </div>
                        </div>
                        <div class="layui-form-item" lay-filter="sex">
                            <label class="layui-form-label">启用开关</label>
                            <div class="layui-input-block">
                                <input type="radio" name="data[status]" value="1" title="启用" <?php if((isset($data['status']) && $data['status']=='1') || !isset($data['status'])){echo 'checked';}?>>
                                <input type="radio" name="data[status]" value="0" title="禁用" <?php if(isset($data['status']) && $data['status']=='0'){echo 'checked';} ?>>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn layui-btn-blue" lay-submit="" lay-filter="ams_submit">提交保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <?=view('footer.html')?>
    <script type="text/javascript">

        layui.use(['layer', 'form', 'jquery'], function () {
            var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;
            

            var url = window.location.href;

            //提交
            form.on('submit(ams_submit)', function (data) {
                $.post(url, data.field, function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, { time: 1500 }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                }, 'json');
                return false;
            });

        });

    </script>
</body>

</html>
